import random

user = {"99999999": {"name": "管理员", "password": 123456, "address": "中华人民共和国北京市昌平区珠江摩尔3号楼1单元1508", "balance": 100,
                     "bank": "中国工商银行昌平支行"}}

while 1:
    print("***********************\n"
          "*        工商银行       *\n"
          "***********************\n"
          "*        1. 开户       *\n"
          "*        2. 存钱       *\n"
          "*        3. 取钱       *\n"
          "*        4. 转账       *\n"
          "*        5. 查询       *\n"
          "*        6. 退出       *\n"
          "***********************"
          )
    choice = input("请选择您要办理的业务：")
    if choice == "1":
        account = str(random.randint(10000000, 99999999))
        if account in user:
            account = str(random.randint(10000000, 99999999))
            print(account)
        if len(user) <= 100:
            name = input("请输入您的姓名：")
            i = len(name)
            if i != 0:
                password = input("请输入您的密码：")
                password_repeat = input("请确认您的密码：")
                n = len(password)
                while n != 6 or password_repeat != password:
                    print("密码输入错误，请重新输入！")
                    password = input("请重新输入您的密码：")
                    password_repeat = input("请再次确认您的密码：")
                    n = len(password)
                if n == 6 and password_repeat == password:
                    country = input("请输入您的国籍！")
                    province = input("请输入您户口所在的省份！")
                    street = input("请输入您户口所在的街道！")
                    door_number = input("请输入您户口所在的门牌号！")
                    address = country + province + street + door_number
                    print(address)
                    balance = input("请输入您的余额：")
                    bank = str("中国工商银行昌平支行")
                    user[account] = dict(name=name, password=password, address=address, balance=balance, bank=bank)
                    print(user)
                    print("开户成功！")
            else:
                print("不能为空！")
        else:
            print("很抱歉！用户已达到上限，无法添加用户！")
    elif choice == "2":
        accounts = input("请输入您的账户：")
        if accounts in user:
            # password = int(input("请输入您的密码："))
            pwd = input("请输入您的密码：")
            user[accounts]["password"] = str(user[accounts]["password"])
            if pwd == user[accounts]["password"]:
                money = input("请输入您存入的金额：")
                U = int(user[accounts]["balance"])
                U += int(money)
                user[accounts]["balance"] = U
                print(user[accounts]["balance"])
                print("存入成功！")
                pass
            else:
                while pwd != user[accounts]["password"]:
                    pwd = input("请您的密码：")
                    PWDs = pwd
                    if PWDs == user[accounts]["password"]:
                        money = input("请输入您存入的金额：")
                        U = int(user[accounts]["balance"])
                        U += int(money)
                        user[accounts]["balance"] = U
                        print(user[accounts]["balance"])
                        print("存入成功！")
                        pass
        else:
            print("该用户账户不存在")
    elif choice == "3":
        account = input("请输入您的账户：")
        if account in user:
            password = input("请输入您的密码：")
            user[account]["password"] = str(user[account]["password"])
            while password != user[account]["password"]:
                print("密码错误请重新输入！")
                password = input("请输入您的密码：")
            else:
                money = int(input("请输入您取出的金额："))
                U = int(user[account]["balance"])
                if money <= U:
                    U -= money
                    user[account]["balance"] = U
                    print("用户剩余金额：", U, "元")
                    print("取钱成功！")
                else:
                    print("您的账户余额不足！")
        else:
            print("该用户账户不存在")
    elif choice == "4":
        account = input("请输入您的账户：")
        if account in user:
            password = input("请输入您的密码：")
            user[account]["password"] = str(user[account]["password"])
            while password != user[account]["password"]:
                print("密码错误请重新输入！")
                password = input("请输入您的密码：")
            else:
                accounts = input("请输入您转入的账户：")
                if accounts in user:
                    if accounts != account:
                        accounts_money = int(input("请输入您转入的金额："))
                        U = int(user[account]["balance"])
                        U1 = int(user[accounts]["balance"])
                        if accounts_money <= U:
                            U1 += accounts_money
                            user[accounts]["balance"] = U1
                            U -= accounts_money
                            user[account]["balance"] = U
                            print("账户余额：", U, "元")
                            print("转账成功！")
                        else:
                            print("余额不足，无法转账！")
                    else:
                        print("操作无效！不予办理！")
                else:
                    print("该用户不存在！")
        else:
            print("账号输入错误！")
    elif choice == "5":
        account = input("请输入您查询的账户：")
        if account in user:
            print("用户存在！")
            password = input("请输入您的密码：")
            user[account]["password"] = str(user[account]["password"])
            while password != user[account]["password"]:
                print("密码错误请重新输入！")
                password = input("请输入您的密码：")
            else:
                print("当前账号：", account)
                print("密码:*******")
                print("余额：", user[account]["balance"], "元")
                print("用户居住地址：", user[account]["address"])
                print("当前账户的开户行：", user[account]["bank"])
        else:
            print("该用户账户不存在!")
    elif choice == "6":
        print("欢迎下次光临！")
        break
    else:
        print("您的输入有误！")
